<?
    require_once("config.php");
    
    $menu = new Menu("Contact Menu");
    $menu->AddItem(new MenuItem("Back","javascript:history.back(-1)",AuthConstants::EVERYONE));
    
    if ($_POST) {
        Functions::PrintHeader("Thank You!");
        if ($_POST['num1'] + $_POST['num2'] != $_POST['num3']) {
            ErrorMessage::Show("Failed Bot Validation","Sorry, your computer was identified as a bot.  Please make sure you have Javascript enabled.");
        }
        else if ($_POST['action'] == "badlisting" && is_numeric($_POST['listingid'])) {
            $message = $_POST['listingid'] . " has been reported as a bad listing.";
            if (MailManager::SendMail(SettingManager::GetSetting("admin email"),"Administrators","Bad Listing Reported",$message)) {
                SuccessMessage::Show("Thank You!","Thank you, this listing has been flagged and will be looked at shortly.");
            }
            else {
                ErrorMessage::Show("ERROR","Sorry, something went wrong when trying to send your message.  You can E-Mail the administrators directly using the contact information on <a href='contact.php'>this page</a>.");
            }
        }
        else if ($_POST['action'] == "contactform") {
            $message = $_POST['name'] . " (E-Mail: " . $_POST['email'] . ") has sent you a message regarding $_POST[subject]<br /><br />$_POST[message]";
            if (MailManager::SendMail(SettingManager::GetSetting("admin email"),"Administrators","Offcampus Contact: $_POST[subject]",$message)) {
                SuccessMessage::Show("Thank You!","Thank you, your message has been received.  If you provided an E-Mail address, you can expect a response within 1-2 business days.");
            }
            else {
                ErrorMessage::Show("ERROR","Sorry, something went wrong when trying to send your message.  You can E-Mail the administrators directly using the contact information on <a href='contact.php'>this page</a>.");
            }
        }
        Functions::PrintFooter();
    }
    else {
        MenuManager::AddMenu("Contact Us",$menu);
        Functions::PrintHeader("Contact Us");
        ?>
        <h2>Contacting Us</h2>
        Have questions? complaints? suggestions?  We take all of these things seriously.  If there's a feature on the site you'd like to see, let us know.  If you've found a problem that needs to be fixed, let us know about that as well.  We do ask, however, that you check the <a href='faq.php'>Frequently Asked Questions</a> to see if your question is answered there before E-Mailing us.
        <br /><br />
        <h2>Contact by Phone</h2>
        The offcampus housing website is maintained by the RPI Union System Administrators.  Therefore, there is no offcampus housing office that you can call.
        <br><br>
        <h2>Contact by E-Mail</h2>
        You can contact the System Administrators at <a href="mailto:offcampus@union.rpi.edu">offcampus@union.rpi.edu</a> or you can fill out the form below.
        <br><br>
        <h2>Found a Listing That's Been Rented Already?</h2>
        <form method="POST" action="contact.php">
            <input type='hidden' name='action' value='badlisting' />
            <table class='cgltable' align='center'>
            <thead>
                <tr>
                    <th colspan='2'>Report Bad Listing</th>
                </tr>
                </thead>
                <tr>
                    <td class='required label'>Listing ID</td>
                    <td><input type='text' name='listingid' size="4" /></td>
                </tr>
                <tfoot>
                <tr>
                    <td colspan='2'><input type='submit' value='Report Bad Listing' /></td>
                </tr>
                </tfoot>
            </table>
        </form>
        <br><br>
        <script type='text/javascript'>
            Event.observe(window,"load", function() {
                $("num3").value = ($("num1").value * 1) + ($("num2").value * 1)
            });
        </script>
        <h2>Need to contact us about something else?</h2>
        <form method="POST" action="contact.php">
            <input type='hidden' id="num1" name='num1' value='<?=rand(0,50)?>' />
            <input type='hidden' id="num2" name='num2' value='<?=rand(0,50)?>' />
            <input type='hidden' id="num3" name='num3' value='' />
            
            <input type='hidden' name='action' value='contactform' />
            <table class='wide cgltable'>
            <thead>
                <tr>
                    <th colspan='2'>Contact</th>
                </tr>
                </thead>
                <tr>
                    <td style='width:200px;' class='required label'>Your Name</td>
                    <td><input type='text' name='name' /></td>
                </tr>
                <tr>
                    <td class='label'>Your E-Mail<br><span style='font-size:7pt; font-weight:normal;'>(If you want us to get back with you)</span></td>
                    <td><input type='text' name='email' /></td>
                </tr>
                <tr>
                    <td class='label'>Subject</td>
                    <td><input type='text' name='subject' /></td>
                </tr>
                <tr>
                    <td class='required label'>Message</td>
                    <td><textarea class='wide' rows='15' name='message'></textarea></td>
                </tr>
                <tfoot>
                <tr>
                    <td colspan='2'><input type='reset' value='Start Over' /><input type='submit' value='Send Message' /></td>
                </tr>
                </tfoot>
            </table>
        </form>
        <?
        Functions::PrintFooter();
    }
?>
